home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / recent2 / yamtools.lha / yamtools1.4 / YTArc2Sent.rexx < prev    next >
OS/2 REXX Batch file  |  1997-03-28  |  16KB  |  436 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                             YTARC2SENT                                     */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /* This script requires YAMTOOLS for it to work. If you don't have YAMTOOLS   */
  8. /* you can get it on Aminet in directory comm/mail.                           */
  9. /*                                                                            */
  10. /* This script allows you to MOVE a SENT message back from an ARCHIVE to the  */
  11. /* SENT folder. You might want to do this if you used YTARCMOVE to archive    */
  12. /* a SENT mail and now want to resend it or forward it.                       */
  13. /*                                                                            */
  14. /*    WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!         */
  15. /*                                                                            */
  16. /* This one as of Yam 1.3.4 MAY be breaking some of Marcel's rules. I really  */
  17. /* don't know. I calculate the new name according to what I have surmised     */
  18. /* Marcel does. No Guarantees that this is entirely compatible with the way   */
  19. /* Marcel intended. Hope so.                                                  */
  20. /*                                                                            */
  21. /* Version 1.1 of YTARC2SENT includes a test for the YAM version, which kill  */
  22. /* this script if the YAM version is greater than 1.3.x  If (and I don't      */
  23. /* think so) there is a need for this script for later versions of YAM, then  */
  24. /* I will rewrite it as necessary. - Dick                                     */
  25. /*                                                                            */
  26. /*----------------------------------------------------------------------------*/
  27. /*                                                                            */
  28. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  29. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  30. /*                                                                            */
  31. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  32. /*would love a postcard from where EVER you live.                             */
  33. /*                                                                            */
  34. /*Instant GEOGRAPHY lesson;)                                                  */
  35. /*                                                                            */
  36. /*                                                                            */
  37. /*POSTCARDS:    Dick Whiting                                                  */
  38. /*              28590 S. Beavercreek Rd.                                      */
  39. /*              Mulino, Oregon 97042                                          */
  40. /*              USA                                                           */
  41. /*                                                                            */
  42. /*----------------------------------------------------------------------------*/
  43. /*                                                                            */
  44. /*               Address Bug Reports or Comments to:                          */
  45. /*                Dick Whiting <dwhiting@europa.com>                          */
  46. /*                           11 March 1997                                    */
  47. /*                                                                            */
  48. /******************************************************************************/
  49. /*
  50. $VER: 1.1 Copyright ©1997 by Dick Whiting
  51. $AUTHOR: Dick Whiting
  52. $DESCRIPTION: Move Sent Mail from an Archive to the Sent Folder
  53. */
  54.  
  55. options results
  56. options failat 21
  57.  
  58. MUIA_List_Format =          0x80423c0a 
  59. MUIA_List_Entries =         0x80421654 
  60. MUIA_VertWeight =           0x804298d0 
  61. MUIA_Window_DepthGadget  =  0x80421923
  62. MUIA_Window_DragBar  =      0x8042045d
  63. MUIA_Window_PublicScreen =  0x804278e4
  64. MUIA_Window_SizeGadget  =   0x8042e33d
  65.  
  66. TRUE=1
  67. FALSE=0
  68.  
  69. MUIV_List_Insert_Active = -1
  70.  
  71. help.SQUIT=''
  72. node.SQUIT=''
  73. help.STEXT=''
  74. node.STEXT=''
  75. help.ARCHF=''
  76. node.ARCHF=''
  77.  
  78. missing='.'
  79. goodver='1.3'                       /* this script is valid for YAM 1.3.x */
  80.  
  81. targanum=2                                  /* should be Sent folder      */
  82.  
  83. Address YAMTOOLS
  84.  
  85. Call CheckYam
  86.  
  87. Call CheckMailList
  88. Call GetSentPath
  89. Call ProcessArchs
  90.  
  91. exit
  92.  
  93. /**************************************************************************/
  94. /*                Check that there is some mail to process                */
  95. /**************************************************************************/
  96. CheckMailList:
  97.  
  98.    list ID MLST ATTRS MUIA_List_Entries
  99.    mcnt=result
  100.    if mcnt=0 then do
  101.       errmsg='You need to CHOOSE mail to Archive'
  102.       Call ErrorMsg
  103.    end
  104.  
  105. Return
  106.  
  107. /**************************************************************************/
  108. /*                   Get full Path Name of Sent Folder                    */
  109. /**************************************************************************/
  110. GetSentPath:
  111.  
  112.    list ID ALST POS targanum
  113.    aline=result
  114.    if aline='' then break
  115.    parse var aline arch ',' size ',' targdir ',' anum ',' rest
  116.  
  117.    if upper(arch)~='SENT' then do
  118.       errmsg='Cannot locate SENT folder'
  119.       Call ErrorMsg
  120.    end
  121.  
  122. Return
  123.  
  124. /**************************************************************************/
  125. /*                           Process Archivals                            */
  126. /**************************************************************************/
  127. ProcessArchs:
  128.  
  129.    infotitle='"YAM Tools Info"'
  130.    infotext='\033nMoving Mail to Sent...'
  131.    infobuttons='"Continue,Interrupt,Abort"'
  132.    showbusy=TRUE
  133.  
  134.    Call InfoWindow
  135.    
  136.    list ID MLST ATTRS MUIA_List_Entries
  137.    mcnt=result
  138.  
  139.    archlist.=missing
  140.    archlist.0=0
  141.    Updlist.=missing
  142.    Updlist.0=0
  143.    acnt=0
  144.  
  145. /**************************************************************************/
  146. /*                     build list of mail to archive                      */
  147. /**************************************************************************/
  148.  
  149.    do i=0 to mcnt-1
  150.       list ID MLST
  151.       mline=result
  152.       if mline='' then break
  153.       parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  154.       acnt=acnt+1
  155.       anum=right(anum,6,'0')
  156.       mnum=right(mnum,6,'0')
  157.       Archlist.0=acnt
  158.       Archlist.acnt=anum mnum file subj
  159.       archlist.0=acnt
  160.       radio ID SQUIT 
  161.       if result~="Continue" then signal ProcessArchsEnd
  162.    end
  163.    Updlist.0=Archlist.0
  164.  
  165.    if acnt=0 then do
  166.       errmsg='You need to SELECT mail to Archive'
  167.       Call ErrorMsg     
  168.    end
  169.  
  170. /**************************************************************************/
  171. /*                      sort the list in preparation                      */
  172. /**************************************************************************/
  173.  
  174.    if show('L','rexxtricks.library') then do    /* use tricks library     */
  175.       call QSORT(archlist)                   /* sort by name, line number */
  176.    end
  177.    else do                                   /* use QuickSort format      */
  178.       call QSORT(1, archlist.0, archlist)      /* sort by name, number    */
  179.    end 
  180.  
  181.    radio ID SQUIT 
  182.    if result~="Continue" then signal ProcessArchsEnd
  183.  
  184. /**************************************************************************/
  185. /*              Loop thru mail verifying nothing has changed              */
  186. /*          do it in reverse order to keep from rearranging list          */
  187. /**************************************************************************/
  188.  
  189.    do i=archlist.0 to 1 by -1                /* process in reverse order  */
  190.       radio ID SQUIT 
  191.       if result~="Continue" then leave    /* skip remaining & do cleanup  */
  192.       anum=word(Archlist.i,1)
  193.       anum=strip(anum,'L','0')
  194.       if anum='' then anum=0
  195.       mnum=word(Archlist.i,2)
  196.       mnum=strip(mnum,'L','0')
  197.       if mnum='' then mnum=0
  198.       file=word(Archlist.i,3)
  199.       subj=subword(Archlist.i,4)
  200.       Updlist.i=anum
  201.       Updlist.i.1=mnum
  202.       Updlist.i.1.1=file
  203.       Updlist.i.1.1.1=subj
  204.       Address YAM 'setfolder 'anum           /* goto folder               */
  205.       Address YAM 'setmail 'mnum             /* set to mail               */
  206.       Address YAM "getmailinfo file"         /* verify filename           */
  207.       xfile=result
  208.       fullfile=xfile                         /* copy complete path/fn     */
  209.       fullstate=statef(fullfile)             /* get info about file       */
  210.       filenote=subword(fullstate,8)          /* complete filenote         */
  211.       if word(filenote,1)~='S' then do
  212.          Updlist.i.1.1.1.1='\033bNot a Sent'
  213.          iterate i
  214.       end
  215.       xlen=length(file)
  216.       xfile=right(xfile,xlen)
  217.       Address YAM "getmailinfo subject"      /* verify subject            */
  218.       xsubj=result      
  219.       xsubj=translate(xsubj,' ',',')
  220.       if file~=xfile | xsubj~=subj then do
  221.          Updlist.i.1.1.1.1='\033berror'
  222.       end 
  223.       else do
  224.            Call MoveIt
  225.       end
  226.    end
  227.    
  228. /**************************************************************************/
  229. /*                    Update target and source folders                    */
  230. /**************************************************************************/
  231.  
  232.    infotext='\033nUpdating Folder Indexes...'
  233.    text ID STEXT LABEL infotext
  234.  
  235.    Address YAM 'setfolder 'targanum          /* set to target folder      */
  236.    Address YAM 'mailupdate'                  /* update the index          */
  237.    oldarch=missing                           /* level break control       */
  238.    do i=1 to Updlist.0
  239.       if Updlist.i~=oldarch then do
  240.          Address YAM 'setfolder ' Updlist.i  /* goto folder               */
  241.          Address YAM 'mailupdate'            /* update the index          */
  242.          oldarch=Updlist.i
  243.       end
  244.    end
  245.  
  246. /**************************************************************************/
  247. /*                   Update list of mail archived/moved                   */
  248. /**************************************************************************/
  249.  
  250.    infotext='\033nUpdating Mail Status...'
  251.    text ID STEXT LABEL infotext
  252.  
  253.    do i=1 to Updlist.0                       /* display status messages   */
  254.       do j=0 to mcnt-1
  255.          list ID MLST POS j
  256.          mline=result
  257.          if mline='' then break
  258.          parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  259.          if Updlist.i=anum & Updlist.i.1=mnum then do
  260.             if Updlist.i.1.1.1.1~=missing then arch=Updlist.i.1.1.1.1
  261.             mline=arch||','||from||','||subj||','||mfor||','||mnum||','||anum||','||file
  262.             list ID MLST POS j STRING mline
  263.             iterate i
  264.          end
  265.       end
  266.    end
  267.  
  268. ProcessArchsEnd:
  269.  
  270.    window ID YTINF CLOSE
  271.  
  272. Return
  273.  
  274. /**************************************************************************/
  275. /* Find the LAST filename in the target dir, calculate new name, do a DOS */
  276. /* COPY command for output and a DOS delete command for the input.        */
  277. /* !! DON'T USE 'i' as a pointer in this routine                          */
  278. /**************************************************************************/
  279. MoveIt:
  280.  
  281.     targfn=right(date('I'),5,'0')
  282.  
  283.    dirlist=showdir(targdir,'FILE')
  284.    highfile='.index'
  285.    do filecnt=1 to words(dirlist)
  286.       if word(dirlist,filecnt) > highfile then do
  287.          highfile=word(dirlist,filecnt)
  288.       end
  289.    end
  290.  
  291.    highname=substr(highfile,1,5)
  292.    highext=substr(highfile,7,3)
  293.  
  294.    if targfn>highname then do
  295.       highname=targfn
  296.       highext='001'
  297.    end
  298.    else do
  299.       highext=highext+1
  300.       highext=right(highext,3,'0')
  301.    end   
  302.  
  303.    if highext='000' then do                    /* gone over 999           */
  304.       highname=right(highname+1,5,'0')         /* use next days date      */
  305.       highext='001'                            /* new series              */
  306.    end
  307.  
  308.    Address Command 'Copy ' fullfile 'TO' targdir'/'highname'.'highext 'QUIET CLONE'
  309.    if rc=0 then do
  310.       Updlist.i.1.1.1.1='\033bmoved'
  311.       Address Command 'Delete ' fullfile 'QUIET'
  312.    end
  313.    else do
  314.       Updlist.i.1.1.1.1='\033berror'
  315.    end
  316.  
  317. Return
  318.  
  319. /**************************************************************************/
  320. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  321. /**************************************************************************/
  322. CheckYAM:
  323.  
  324.    if ~show('p','YAMTOOLS') then do
  325.       errmsg='You need YAMTOOLS running to use YTArchive'
  326.       say errmsg
  327.       exit
  328.    end
  329.  
  330.    if ~show('p','YAM') then do
  331.       errmsg='You need YAM running to use YTArchive'
  332.       Call ErrorMsg
  333.       exit
  334.    end
  335.  
  336.    Address YAM 'info version'               /* check YAM's version        */
  337.    yamver=word(result,3)
  338.  
  339.    if left(yamver,3)~=goodver then do       /* only 1.3.x or lower valid  */
  340.       errmsg='This script is not valid for YAM 'yamver
  341.       Call ErrorMsg
  342.       exit     
  343.    end
  344.  
  345.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  346.  
  347.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  348.     screen=result
  349.     if screen='' then screen='Workbench'
  350.  
  351. Return
  352.  
  353. /******************************************************************************/
  354. /*  Display ERROR message and EXIT.                                           */
  355. /******************************************************************************/
  356. ErrorMsg:
  357.  
  358.    window ID YTINF CLOSE
  359.  
  360.    request ID ERRM GADGETS '"OK"' errmsg
  361.  
  362.    exit
  363.  
  364. Return
  365.  
  366. /******************************************************************************/
  367. /*  Display list of Archives for archive target selection.                    */
  368. /******************************************************************************/
  369. ArchWindow:
  370.  
  371.    window ID YTARC TITLE '"YAM Tools Archiver"',
  372.           COMMAND '"window ID YTARC close"' PORT YAMTOOLS,
  373.           ATTRS MUIA_Window_PublicScreen screen
  374.  
  375.         group
  376.          group
  377.                text LABEL "\033c\033bSelect Target Folder For Archiving"
  378.          endgroup
  379.          group 
  380.             list ID ARCHF COMMAND '"YTArchive.rexx %s"', 
  381.                HELP help.ARCHF NODE node.ARCHF,
  382.                TITLE '"\033bYam Folder Name,\033bNumber,"',
  383.                INSERT NODUP, 
  384.                ATTRS MUIA_List_Format '"BAR,P=\033r,WEIGHT=0 MAXWIDTH=0 MINWIDTH=0"'
  385.          endgroup
  386.         endgroup
  387.  
  388.    endwindow
  389.  
  390. Return
  391.  
  392. /******************************************************************************/
  393. /*  Simple information/error message window.                                  */
  394. /******************************************************************************/
  395. InfoWindow:
  396.  
  397.    window ID YTINF TITLE '"YAM Archiver Info"' ATTRS MUIA_Window_PublicScreen screen,
  398.           MUIA_Window_SizeGadget FALSE MUIA_Window_DragBar FALSE,
  399.           MUIA_Window_DepthGadget FALSE
  400.  
  401.       group 
  402.          group 
  403.             text ID STEXT HELP help.STEXT  NODE node.STEXT LABEL infotext
  404.          endgroup
  405.          if showbusy then do
  406.             group
  407.                object CLASS '"Busy.mcc"' ATTRS MUIA_VertWeight 25
  408.             endgroup
  409.          end
  410.          if infobuttons ~='' then do
  411.             group HORIZ
  412.                group 
  413.                   space HORIZ 
  414.                endgroup
  415.                group 
  416.                   radio ID SQUIT HELP help.SQUIT  NODE node.SQUIT LABELS infobuttons
  417.                endgroup
  418.                group 
  419.                   space HORIZ 
  420.                endgroup
  421.             endgroup
  422.          end
  423.          else do
  424.             group 
  425.                space HORIZ 100
  426.             endgroup
  427.          end
  428.       endgroup
  429.    endwindow
  430.  
  431. Return
  432.  
  433. /**************************************************************************/
  434. /*                           End of Active Code                           */
  435. /**************************************************************************/
  436.